package baiduClub.schedule;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class LoginActivity extends Activity{
	
	public static final String flag = "baiduClub.schedule.LoginActivity";
	private TextView loginButton;
	private TextView exitButton;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login_layout);
		
		loginButton = (TextView)findViewById(R.id.loginButton);
		loginButton.setOnClickListener(new LoginButtonListener());
		
		exitButton = (TextView) findViewById(R.id.cancelButton);
		exitButton.setOnClickListener(new View.OnClickListener() 
		{
			public void onClick(View v) 
			{
				// TODO Auto-generated method stub
				finish();
			}
		});
		
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if(requestCode==0&&resultCode==RESULT_OK)
		{
			finish();
		}
	}



	class LoginButtonListener implements OnClickListener
	{

		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent = new Intent();
			
			SharedPreferences settings = getSharedPreferences("baiduClub.schedule", 0);
			String xmlDir = settings.getString("xmlDir", null);
			if (xmlDir != null)
			{
				intent.setClass(LoginActivity.this, MainActivity.class);
				startActivityForResult(intent, 0);
			}
			else 
			{
				intent.setClass(LoginActivity.this, FileBrownser.class);
				startActivityForResult(intent, 0);
			}
		}
	}
}
